<template>
  <div class="app-container">
    <basic-container v-show="showSearch">
      <common-search @handleQuery="handleQuery" @resetQuery="resetQuery">
        <el-form :model="queryParams" ref="queryForm" :inline="true" size="mini" label-width="100px">
          <el-form-item label="业务代码" prop="businessType">
            <el-select v-model.trim="queryParams.businessType" placeholder="请选择业务代码" clearable>
              <el-option v-for="dict in dict.type.sys_bill_business_type" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="业务名称" prop="businessName">
            <el-input v-model.trim="queryParams.businessName" placeholder="请输入业务名称" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="进出口" prop="iEFlag">
            <el-select v-model.trim="queryParams.iEFlag" placeholder="请选择进出口" clearable>
              <el-option v-for="dict in dict.type.sys_i_e_flag" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="贸易类型" prop="tradeType">
            <el-select v-model.trim="queryParams.tradeType" placeholder="请选择贸易类型" clearable>
              <el-option v-for="dict in dict.type.trade_type_list" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="单证类型" prop="billType">
            <el-select v-model.trim="queryParams.billType" placeholder="请选择单证类型" clearable>
              <el-option v-for="dict in dict.type.bill_type_list" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="单证分类" prop="billCategory">
            <el-select v-model.trim="queryParams.billCategory" placeholder="请选择单证分类" clearable>
              <el-option v-for="dict in dict.type.business_type_category" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="运输方式" prop="trafMode">
            <el-select v-model.trim="queryParams.trafMode" placeholder="请选择运输方式" clearable>
              <el-option v-for="dict in dict.type.sys_filed_type" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
        </el-form>
      </common-search>
    </basic-container>

    <basic-container>
      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <!-- 列表 -->
      <basic-table ref="tableList" :columns="columns" :tableData="tableData" :total="pageParams.total"
        @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :loading="loading"
        :needCheckbox="true" @selectionChange="handleSelectionChange">



        <template #iEFlag="scope">
          <dict-value :list="dict.type.sys_i_e_flag" :dictCode="scope.row.iEFlag"></dict-value>
        </template>


        <template #tradeType="scope">
          <dict-value :list="dict.type.trade_type_list" :dictCode="scope.row.tradeType"></dict-value>
        </template>


        <template #billType="scope">
          <dict-value :list="dict.type.bill_type_list" :dictCode="scope.row.billType"></dict-value>
        </template>


        <template #billCategory="scope">
          <dict-value :list="dict.type.business_type_category" :dictCode="scope.row.billCategory"></dict-value>
        </template>


        <template #trafMode="scope">
          <dict-value :list="dict.type.sys_filed_type" :dictCode="scope.row.trafMode"></dict-value>
        </template>

        <template #customsStateCode="scope">
          <dict-value :list="dict.type.mft_biz_mode" :dictCode="scope.row.customsStateCode"></dict-value>
        </template>


        <template #operate="scope">
          <div class="option-menu">
            <el-button type="text" size="mini" class="table-edit" @click="handleAddEdit('edit', scope.row)"
              v-hasPermi="['billsdecl:billBusinessType:edit']">
              编辑
            </el-button>
            <el-button type="text" size="mini" class="table-edit" @click="handleDelete(scope.row)"
              v-hasPermi="['billsdecl:billBusinessType:remove']">
              删除
            </el-button>
            <el-button type="text" size="mini" class="table-edit" @click="handleDetail(scope.row)">
              详情
            </el-button>
          </div>
        </template>
      </basic-table>
    </basic-container>

    <!-- 新增、编辑 -->
    <add-edit ref="addEdit" :dialogType="dialogType" :rowData="rowData" :dict="dictProp" @handleQuery="handleQuery" />

    <!-- 详情 -->
    <detail-dialog ref="detail" :detailId="detailId" :dict="dictProp"></detail-dialog>

  </div>
</template>

<script>
  import {
    listBillBusinessType,
    delBillBusinessType,
    exportBillBusinessType
  } from "@/api/billsdecl/billBusinessType";
  import addEdit from "./components/addEdit";
  import detailDialog from "./components/detailDialog";
  export default {
    name: "BillBusinessType",
    components: {
      addEdit,
      detailDialog
    },
    dicts: ['sys_bill_business_type', 'sys_i_e_flag', 'trade_type_list', 'bill_type_list', 'business_type_category',
      'sys_filed_type','mft_biz_mode'
    ],
    data() {
      return {
        // 显示搜索条件
        showSearch: true,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          businessType: null,
          businessName: null,
          iEFlag: null,
          tradeType: null,
          billType: null,
          billCategory: null,
          trafMode: null,
        },
        // 遮罩层
        loading: true,
        // 列表数据
        tableData: [],
        columns: [{
            prop: "businessType",
            label: "业务代码",
            align: "center"
          },
          {
            prop: "businessName",
            label: "业务名称",
            align: "center"
          },

          {
            prop: "iEFlag",
            label: "进出口",
            align: "center",
            slot: true
          },
          {
            prop: "customsStateCode",
            label: "通关类型",
            align: "center",
            slot: true
          },
          {
            prop: "tradeType",
            label: "贸易类型",
            align: "center",
            slot: true
          },
          {
            prop: "billType",
            label: "单证类型",
            align: "center",
            slot: true
          },
          {
            prop: "billCategory",
            label: "单证分类",
            align: "center",
            slot: true
          },
          {
            prop: "trafMode",
            label: "运输方式",
            align: "center",
            slot: true
          },
          {
            prop: "createBy",
            label: "创建人",
            align: "center"
          },

          {
            prop: "createTime",
            label: "创建时间",
            align: "center"
          },

          {
            prop: "operate",
            label: "操作",
            slot: true,
            width: 140,
            fixed: "right",
          },
        ],
        pageParams: {
          total: 0,
        },
        rowData: {},
        detailId: "",
        dialogType: "",
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        //详情显示的时候，表单编辑禁用
        isViewDisabled: false,

        // 单证业务类型表格数据
        billBusinessTypeList: [],
      };
    },
    computed: {
      dictProp() { //字典list，为避免子组件重复调接口获取，用computed计算传值
        return {
          type: this.dict.type
        }
      }
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询单证业务类型列表 */
      getList() {
        this.loading = true;
        listBillBusinessType(this.queryParams).then(response => {
          this.tableData = response.rows;
          this.pageParams.total = response.total;
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.$refs.tableList.pageParams.currentPage = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 分页
      handleSizeChange(val) {
        this.queryParams.pageSize = val.pageSize;
        this.getList();
      },
      handleCurrentChange(val) {
        this.queryParams.pageNum = val.currentPage;
        this.getList();
      },
      // 新增/编辑
      handleAddEdit(type, row) {
        this.dialogType = type;
        if (row) {
          this.rowData = JSON.parse(JSON.stringify(row));
        }
        this.$refs.addEdit.open();
      },
      // 详情
      handleDetail(row) {
        this.detailId = row.id;
        this.$nextTick(() => {
          this.$refs.detail.open(row);
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除单证业务类型编号为"' + ids + '"的数据项？').then(function() {
          return delBillBusinessType(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      }
    }
  };
</script>



<style type="text/css">
  .el-form-item .el-select {
    width: 100%;
  }
</style>
